/**
 * 
 *//*

package jaxrClients;

import java.net.PasswordAuthentication;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessLifeCycleManager;
import javax.xml.registry.BusinessQueryManager;
import javax.xml.registry.CapabilityProfile;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.FindQualifier;
import javax.xml.registry.JAXRException;
import javax.xml.registry.JAXRResponse;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.Classification;
import javax.xml.registry.infomodel.ClassificationScheme;
import javax.xml.registry.infomodel.Concept;
import javax.xml.registry.infomodel.ExternalLink;
import javax.xml.registry.infomodel.InternationalString;
import javax.xml.registry.infomodel.Organization;
import javax.xml.registry.infomodel.Service;
import javax.xml.registry.infomodel.ServiceBinding;
import javax.xml.registry.infomodel.SpecificationLink;

*/
/**
 * @author Navneet Rai
 *
 *//*

public class ObtainBusinessLifeCycleAndBusinessQueryManager {
	private BusinessQueryManager businessQueryManager = null;
	private BusinessLifeCycleManager businessLifeCycleManager = null;
	private Connection connection = null;
	*/
/**
	 * @param args
	 *//*

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	*/
/*
	* Establish a connection to a JAXR provider.
	* Set authentication information, communication preference.
	* Get business-focused discovery and publish interfaces. 
	*//*

	public void makeConnection(String username, String password) {
	  // URLs for RegistryServer 
	  String queryURL = "http://localhost/RegistryServerServlet";
	  String publishURL = "http://localhost/RegistryServerServlet";
	 
	  */
/*
	  * Define connection configuration properties.
	  * For simple queries, you need the query URL.
	  * To use a life-cycle manager, you need the publish URL.
	  *//*

	  Properties props = new Properties();
	  props.setProperty("javax.xml.registry.queryManagerURL", queryURL);
	  props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishURL);
	  try {
	    // Create the connection, passing it the configuration properties
	    ConnectionFactory factory = ConnectionFactory.newInstance();
	    factory.setProperties(props);
	    connection = factory.createConnection();
	    System.out.println("Created connection to registry");
	 
	    // Get registry service and managers
	    RegistryService rs = connection.getRegistryService();
	 
	    // Get the capability profile
	    CapabilityProfile capabilityProfile = rs.getCapabilityProfile();
	    if (capabilityProfile.getCapabilityLevel() == 0) {
	      System.out.println("Capability Level 0, Business Focused API");
	    }
	 
	    // Get manager capabilities from registry service
	    businessQueryManager = rs.getBusinessQueryManager();
	    businessLifeCycleManager = rs.getBusinessLifeCycleManager();
	    System.out.println("Got registry service, query manager and lifecycle manager");
	 
	    // Set client authorization information for privileged registry operations
	    PasswordAuthentication passwdAuth = new PasswordAuthentication(username, password.toCharArray());
	    Set creds = new HashSet();
	    creds.add(passwdAuth);
	 
	    // Set credentials on the JAXR provider 
	    connection.setCredentials(creds);
	    System.out.println("Established security credentials");
	 
	    // Set communication preference
	    connection.setSynchronous(true);
	 
	  } catch (Exception e) {
	    e.printStackTrace();
	    if (connection != null) {
	      try {
	        connection.close();
	      } catch (JAXRException je) {
	      }
	    } 
	  }
	}
	public void findOrganizations() throws JAXRException {
		 
		  // Search criteria -- Organizations found will return in this sort order
		  Collection findQualifiers = new ArrayList();
		  findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
		 
		  // Query the JAXR taxonomy service
		  ClassificationScheme naics = businessQueryManager.findClassificationSchemeByName(
		                 findQualifiers, "ntis-gov:naics:1997");
		 
		  // Create the classification that will be a parameter to findOrganization() method
		  Classification computerSystemsDesign = businessLifeCycleManager.createClassification(
		                 naics, "Computer Systems Design and Related Services", "5415");

		  // Query the taxonomy service
		  ClassificationScheme geography = businessQueryManager.findClassificationSchemeByName(
		                 findQualifiers, "iso-ch:3166:1999");
		 
		  // Create the classification passed as a parameter to findOrganization() method.
		  Classification us = businessLifeCycleManager.createClassification(
		                 geography, "United States", "US");
		 
		  // Add classifications to the classifications collection parameter
		  Collection classifications = new ArrayList();
		  classifications.add(computerSystemsDesign);
		  classifications.add(us);
		 
		  // Invoke the findOrganizations() method on BusinessQueryManager
		  BulkResponse bulkResponse = businessQueryManager.findOrganizations(
		                 findQualifiers, null, classifications, null, null, null);
		 
		  if (bulkResponse.getStatus() == JAXRResponse.STATUS_SUCCESS) {
		    System.out.println("Found Organization located in the United States ");
		    System.out.println("categorized Computer Systems Design and Related Service ");
		  }
		}
	
	*/
/**
	 * The getOrganizationDetail() method demonstrates how a JAXR client can obtain full Organization 
	 * details using JAXr and UDDI APIs
	 * @param bulkResponse
	 * @throws JAXRException
	 *//*

	public void getOrganizationDetail(BulkResponse bulkResponse) throws JAXRException { 
		  // Get a collection of Organizations from BulkResponse
		  Collection organizations = bulkResponse.getCollection();

		  // Iterate through the collection to get an individual Organization
		  Iterator orgIter = organizations.iterator();

		  while (orgIter.hasNext()) {
		    Organization organization = (Organization) orgIter.next();

		    // Get a collection of Services from an Organization
		    Collection services = organization.getServices();

		    // Iterate through the collection to get an individual Service
		    Iterator serviceIter = services.iterator();

		    while (serviceIter.hasNext()) {
		      Service service = (Service) serviceIter.next();
		 
		      // Get a collection of ServiceBindings from a Service
		      Collection serviceBindings = service.getServiceBindings();

		      // Iterate through the collection to get an individual ServiceBinding
		      Iterator sbIter = serviceBindings.iterator(); 
		      while (sbIter.hasNext()) {
		        ServiceBinding serviceBinding = (ServiceBinding) sbIter.next();
		 
		        // Get URI of the service. You can access the service through this URI.
		        String accessURI = serviceBinding.getAccessURI();
		        System.out.println("Access the service " + service.getName().getValue() 
		                    + " at this URI " + accessURI);
		 
		        // Get a collection of SpecificationLinks from a ServiceBinding. 
		        // SpecificationLinks provide further technical details needed to access the service.
		        Collection specificationLinks = serviceBinding.getSpecificationLinks();

		        // Iterate through the collection to get an individual SpecificationLink
		        Iterator linkIter = specificationLinks.iterator();
		        while (linkIter.hasNext()) {
		          SpecificationLink specificationLink = (SpecificationLink) linkIter.next();
		 
		          // Get a collection of ExternalLinks from SpecificationLink 
		          // An ExternalLink points to technical detail necessary to invoke the service
		          Collection externalLinks = specificationLink.getExternalLinks();

		          // Iterate through the collection to get an ExternalLink
		          Iterator elinkIter = externalLinks.iterator();
		          while (elinkIter.hasNext()) {
		            ExternalLink externalLink = (ExternalLink) elinkIter.next();

		            // The externalURI is the pointer to the technical details 
		            // necessary to invoke the service
		            String externalURI = externalLink.getExternalURI();
		            System.out.println(
		                " Use the technical detail at this URI, " 
		                + externalURI + " to invoke the service, "
		                + service.getName().getValue());
		          }
		 
		          // Obtain usage description
		          InternationalString usageDescription = specificationLink.getUsageDescription();

		          // Any parameters necessary to invoke service are in usageParameter collection
		          Collection usageParameters = specificationLink.getUsageParameters();

		          // Get the specification concept from the specification link
		          // This specificationConcept is equivalent to the tModel registered as 
		          // the technical specification
		          Concept specificationConcept = (Concept) specificationLink.getSpecificationObject();
		        }
		      }
		    }
		  }
		}
}
*/
